package com.jianyun.jyzs.http;

import android.util.Log;

import com.jianyun.jyzs.bean.AddressList;
import com.jianyun.jyzs.bean.MeUserInfo;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by yangshijun on 2018/6/4.
 */

public class ContactHelper {
    private static int pageCnt;

    public interface OngetListener {
        void onSuccess(AddressList response);

        void onFailed(String msg);
        void setCut(int cut);

    }
    int pageIndex=1;
    public static void getAddressList(String enterpriseCode,
                                      String userid, String pageIndex, final OngetListener ongetListener) {
        Api api = RetrofitHelper.builderErpHttp().create(Api.class);

        api.getAddressList("getAddressList", enterpriseCode, userid, pageIndex)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<AddressList>() {
                    @Override
                    protected void onResponse(AddressList response) {
                        if (response.isResult()){
                            ongetListener.setCut(response.getPageCnt());
                            //pageCnt = response.getPageCnt();
                            //ongetListener.onSuccess(response);
                        }else {
                            ongetListener.onFailed(response.getMessage());
                        }
                    }

                    @Override
                    protected void onException(String msg) {
                        ongetListener.onFailed(msg);
                    }
                });
    }

    public void getUserInfo(String enterpriseCode, String userId) {

        Api api = RetrofitHelper.builderErpHttp().create(Api.class);
        api.getUserinfo("getUserInfo", enterpriseCode, userId,"jyzs","Android","1.0.2")
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<MeUserInfo>() {
                    @Override
                    protected void onResponse(MeUserInfo response) {
                        if (response.isResult()){
                            Log.i("test", "o:" + response.toString());
                            //onGetUserInfoListener.onSuccess(response);
                           // LoginCache.getInstance().setUserDetaileInfo(response);
                        }
                    }

                    @Override
                    protected void onException(String msg) {
                        //onGetUserInfoListener.onException(msg);
                    }
                });
    }
}
